package net.hn.hnms.biz.energy.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import net.hn.hnms.biz.energy.domain.WaterRecord;
import net.hn.hnms.biz.energy.request.WaterRecordReq;
import net.hn.hnms.biz.energy.vo.WaterRecordVo;
import net.hn.hnms.biz.energy.vo.WaterTotalVo;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

public interface WaterRecordMapper extends BaseMapper<WaterRecord> {
    @Update("<script>" +
            " update  water_record set  del_flag = '1' " +
            " where record_id in" +
            " <foreach collection=\"list\" item=\"value\" separator=\",\" open=\"(\" close=\")\">\n" +
            "#{value}" +
            "</foreach>" +
            "</script>")
    void updateDeleteByIds(@Param("list") List<String> list);

    @Select("<script>" +
            " select \"sum\"(water_charges) waterCharges,\"sum\"(water_consumption) waterConsumption from water_record " +
            " where del_flag = '0'  " +
            " <if test='query.waterSupplyCompanyId != null and query.waterSupplyCompanyId != \"\" '>"+
            " and water_supply_company_id = #{query.waterSupplyCompanyId} " +
            " </if>"+
            "</script>")
    WaterTotalVo getTotal(@Param("query") WaterRecordReq waterRecordReq);

    @Select("<script>" +
            " select wr.record_id recordId,wr.water_consumption waterConsumption,wr.sewage_treatment_charges sewageTreatmentCharges, " +
            " wr.water_charges waterCharges,wr.water_resources_charges waterResourcesCharges,wr.water_supply_company_id waterSupplyCompanyId, " +
            " wr.remark remark,wsc.water_supply_company_name waterSupplyCompanyName,wr.create_time createTime,wr.water_date waterDate from water_record wr LEFT JOIN water_supply_company wsc on wr.water_supply_company_id = wsc.water_supply_company_id " +
            " where wr.del_flag = '0'  " +
            " <if test='query.mineCode != null and query.mineCode != \"\" '> "+
            " and wr.mine_code = #{query.mineCode} " +
            " </if>"+
            " <if test='query.waterSupplyCompanyId != null and query.waterSupplyCompanyId != \"\" '> "+
            " and wr.water_supply_company_id = #{query.waterSupplyCompanyId} " +
            " </if>"+
            " order by wr.water_date desc </script>")
    Page<WaterRecordVo> selectPageList(Page<Object> build, @Param("query") WaterRecordReq waterRecordReq);

    @Select("<script>SELECT SUM" +
            "    ( water_consumption ) AS waterConsumptionCount," +
            "    SUM ( sewage_treatment_charges ) AS sewageTreatmentChargesCount," +
            "    SUM ( water_charges ) AS waterChargesCount," +
            "    SUM ( water_resources_charges ) AS waterResourcesChargesCount " +
            "FROM" +
            "    water_record " +
            "WHERE" +
            "    del_flag = '0' " +
            "    AND mine_code = #{mineCode} </script>")
    WaterRecordVo getWaterRecordByMineCode(@Param("mineCode") String mineCode);
}
